package com.example.weizix.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.weizix.R;
import com.example.weizix.base.BaseRlAdapter;
import com.example.weizix.bean.columnBean;

import java.util.ArrayList;
import java.util.List;

public class CoumnAdapter extends RecyclerView.Adapter {


    private final Context context;
    private final ArrayList<columnBean.DataBean> list;

    public CoumnAdapter(Context context, ArrayList<columnBean.DataBean> list) {

        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_counm, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ViewHolder holder1 = (ViewHolder) holder;
        holder1.tv.setText(list.get(position).getName());
        Glide.with(context).load(list.get(position).getThumbnail()).into(holder1.iv);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void addData(List<columnBean.DataBean> data) {
        list.addAll(data);
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv;
        private TextView tv;
        public ViewHolder(View itemView) {
            super(itemView);
            iv=itemView.findViewById(R.id.iv);
            tv=itemView.findViewById(R.id.tv);
        }
    }
}
